package com.xubeizhi.controller;

import com.xubeizhi.common.Result;
import com.xubeizhi.entity.Category;
import com.xubeizhi.service.CategoryService;
import com.xubeizhi.vo.CategoryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/system/category")
@CrossOrigin
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @PostMapping("/create")
    public Result createCategory(@RequestBody Category category){
        return categoryService.create(category);
    }

    @GetMapping("/list")
    public Result listCategory(CategoryVo category){
        return categoryService.getCategory(category);
    }

    @GetMapping("/detail")
    public Result getCategoryById(Integer id){
        return categoryService.getCategoryById(id);
    }

    @PutMapping("/update")
    public Result updateCategory(@RequestBody Category category){
        return categoryService.updateCategory(category);
    }

    @DeleteMapping("/delete")
    public Result deleteById(Integer id){
        return categoryService.deleteCategoryById(id);
    }
}
